<?php
class Postalcode_model extends CI_Model
{
	public function __construct()
	{
		$this->load->database();
		$this->load->config('config_maitai_postalcode');	
	}
	
	public function get_province()
	{
		$this->db->cache_on();
		//$query = $this->db->get_where($this->config->item('maitai_province'), array('upper_promo_level' => '0', 'promo_level' => '1', 'active_status'=>'1'));
		$query = $this->db->get($this->config->item('maitai_table_province'));
		$this->db->cache_off();
		return $query->result_array();
		//$this->db->close();
	}
	
	public function get_town($province_id)
	{
		$this->db->cache_on();
		$query = $this->db->get_where($this->config->item('maitai_table_town'), array('provinceId' => $province_id));
		$this->db->cache_off();
		return $query->result_array();
		//$this->db->close();
	}
	
	public function get_barangay($town_id)
	{
		$this->db->cache_on();
		$query = $this->db->get_where($this->config->item('maitai_table_barangay'), array('townId' => $town_id));
		$this->db->cache_off();
		return $query->result_array();
		//$this->db->close();
	}
	
	public function get_pcode($town_id, $barangay_id)
	{
		$this->db->cache_on();
		$query = $this->db->get_where($this->config->item('maitai_table_pcode'), array('townId' => $town_id, 'barangayId' => $barangay_id));
		$this->db->cache_off();
		return $query->result_array();
		//$this->db->close();
	}
}